#!/bin/bash
DST="$5"

if [ "$2" != "0" ]; then
	abis="armeabi
	armeabi-v7a
	x86"
	has_do=0
	for abi in $abis
	do
		if [ -d $DST/lib/$abi ]; then
			unzip $4/data/plugin/c/$2/$abi/RiskStub -d $DST/lib/$abi
			has_do=1
		else
			echo "WARN drop $abi"
		fi
	done
	if [ "$has_do" != "1" ]; then
		must_dir=$DST/lib/armeabi/
		mkdir -p $must_dir
		unzip $4/data/plugin/c/$2/armeabi/RiskStub -d $must_dir
	fi

	
	#判断assert文件是否存在，然后拷贝v0和apk文件到assert
	assets_dir=$DST/assets/
	if [ ! -d $assets_dir ]; then
		mkdir -p $assets_dir
	fi
	/bin/cp $4/data/plugin/java/$3/RiskStub $assets_dir/RiskStub
	/bin/cp $4/data/plugin/version $assets_dir/RiskStub.version
fi


sed -i 's|.*</application>|<activity android:name="com.bangcle.everisk.stub.NewActivity" android:background="#00ffffff" android:label="xxxxx" ></activity>\n&|'  $DST/AndroidManifest.xml
sed -ri "s|(<\s*meta-data[^>]*:\s*value\s*=\s*\")([0-9]{11,})(\"[^>]*/>)|\1\2\\\\0\3|g" $DST/AndroidManifest.xml

unzip -o $1 AndroidManifest.xml

